// 建立连接
function connectSocket(chatId) {
	var socketTask = uni.connectSocket({
		// url: 'ws://192.168.0.50:9003/websocket/' + chatId,
		url: 'ws://1.94.161.87:9003/websocket/' + chatId,
		success: (res) => {
			console.log('WebSocket连接成功！', res);
		},
		fail: (err) => {
			console.log('WebSocket连接失败！', err);
		}
	})
	return socketTask
}
// 发送消息
function sendSocketMessage(msg, socketTask, messageType, roleType, sessionType) {
	let info = {
		message: msg,
		sessionType: sessionType,
		messageType: messageType,
		roleType: roleType
	}
	console.log('发送消息msg111', JSON.stringify(info));
	return new Promise((reslove, reject) => {
		socketTask.send({
			data: JSON.stringify(info),
			success(res) {
				console.log('发送成功----');
			},
			fail(res) {
				console.log('发送失败---', res);
				reject(res)
			}
		})
	})
}
module.exports = {
	connectSocket: connectSocket,
	sendSocketMessage: sendSocketMessage,
}